package com.vehicle_information_management_system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vehicle_information_management_system.pojo.DepartmentInfo;
import com.vehicle_information_management_system.service.impl.DepartmentInfoServiceImpl;
import com.vehicle_information_management_system.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/departmentInfo")
public class DepartmentInfoController {
    @Autowired
    private DepartmentInfoServiceImpl departmentInfoService;

    @RequestMapping("/list")
    public Result<?> listPage(@RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              @RequestParam(defaultValue = "") String search){
        IPage<DepartmentInfo> page=departmentInfoService.listPage(pageNum,pageSize,search);
        return Result.success(page);
    }
    @RequestMapping("/add")
    public Result<?> add(@RequestBody DepartmentInfo departmentInfo){
        try{
            departmentInfoService.add(departmentInfo);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
        return Result.success("添加成功");
    }
    @RequestMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Integer id){
        try{
            departmentInfoService.delete(id);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
        return Result.success("删除成功");
    }
    @RequestMapping("/update")
    public Result<?> update(@RequestBody DepartmentInfo departmentInfo){
        try{
            departmentInfoService.update(departmentInfo);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
        return Result.success("修改成功");
    }
}
